package com.whynot.frame.basic.util;


import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 描    述:会话信息
 * 创建时间: 2018/07/13
 */
public class WebUtil {

    public static String getUserName(HttpServletRequest request){
        Object obj = request.getAttribute("userName");
        return StringUtils.isNotEmpty(obj) ? obj.toString():"";
    }

    public static Map<String,Object> getUser(){
        Subject subject = SecurityUtils.getSubject();
        Map map = (Map) subject.getPrincipal();
        if(StringUtils.isEmpty(map) && map.size() <=0 ){
            return  null;
        }
        return map;
    }

    public static String gwtUserId(){
        Map<String,Object> map = getUser();
        if(StringUtils.isEmpty(map) && map.size() <=0 ){
            return  null;
        }
        return map.get("id").toString();
    }
}